import { Component, OnInit } from '@angular/core';
import { NzNotificationService } from 'ng-zorro-antd';
import { Router, ActivatedRoute } from '@angular/router';
import { HttpServcie } from '../../../service/http.service';
import { Config } from '../../../service/config';
import { ElevatorAppraisalBean } from './bean/elevator-appraisal.bean';
import { el } from "@angular/platform-browser/testing/src/browser_util";
import { NzModalService, NzModalSubject } from 'ng-zorro-antd';
@Component({
  selector: 'elevator-appraisal',
  templateUrl: './elevator-appraisal.html',
  styleUrls: ['./elevator-appraisal.scss']
})
/**
 *  电梯评价表
 */
export class  ElevatorAppraisalPage implements OnInit {
   data: any;
   list: any = [{}];//返回的数据
   elevatorAppraisalBean: ElevatorAppraisalBean = new ElevatorAppraisalBean();
   types: any = []; //电梯类型
   config=Config;
   modelTitle: string;//模态标题
   currentModal: NzModalSubject;
   isActive : number = 1;
   inValue: any={};
   elevatorId:string;
  total: string;
  constructor(
    private httpServcie: HttpServcie,
    private router: Router,
    private _notification: NzNotificationService,
    private nsub: NzModalSubject,
    private modalService: NzModalService,
    private activatedRoute: ActivatedRoute,

  ) {
    this.activatedRoute.params.subscribe(data => {
      //深度 clone 一下，否则不能修改
      this.inValue = Object.assign({}, data);
    });
    this.elevatorAppraisalBean.pageSize = 10;
    this.elevatorAppraisalBean.currentPage = 1;
    this.elevatorAppraisalBean.elevatorId = this.inValue.elevatorId;
  }

  ngOnInit() {
    this.query();
  }

  query() {
    //查询当前电梯的评价
    this.httpServcie.getElevatorAppraisal(this.elevatorAppraisalBean).subscribe(data=>{
      if(data.status==200){
        this.list = data.data.list;
        this.total = data.data.total;

      } else if (data.status === 401) {
        this.router.navigateByUrl('/login');
        return;
      } else {
        // 异常
        this._notification.create('error', '错误提示', data.message);
      }
    }, error => {
      console.log(JSON.stringify(error))
    })
  }
  //table加载数据时
  displayDataChange($event) {
    this.list = $event;
  }


  //分页
  nzPageSizeChange(event) {
    this.elevatorAppraisalBean.pageSize = event;
    this.elevatorAppraisalBean.currentPage = 1;
    this.query();

  }
  //输入框的方法
  nzPageIndexChange(event) {
    this.elevatorAppraisalBean.currentPage = event;
    this.query();
  }

  //当前页
  nzPageIndexClickChange(event) {
    this.elevatorAppraisalBean.currentPage = event;
    this.query();
  }
  
  toBack(){
		window.history.back() 
	   // this.router.navigate
  }
  
}
